package j.framework.core;

import j.util.ForUtils;
import j.util.New;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * User: jason
 * Date: 2014/11/7 16:51
 */
public class Dict implements Serializable {
    private static final long serialVersionUID = 20120518140823L;
    private String code;//字典代码
    private String name;//字典名称
    public final Map<String,DictItem> items = New.lMap();
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public List<DictItem> getItems(){
        final List<DictItem> items = New.list(this.items.size());
        ForUtils.forMap(this.items, new ForUtils.ForHandler<Map.Entry<String, DictItem>>() {
            @Override
            public int doFor(int index, Map.Entry<String, DictItem> item) {
                items.add(item.getValue());
                return 0;
            }
        });
        return items;
    }
    @Override
    public int hashCode() {
        return code.hashCode();
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Dict dict = (Dict) o;

        if (code != null ? !code.equals(dict.code) : dict.code != null) return false;

        return true;
    }
}
